<?php
/**
 * Login_Model_Registred
 * registred model
 *
 * @author Adrian Stolarski
 */
class Login_Model_Registred implements Login_Data_Mainable, Login_Model_Checkable, 
        Login_Model_Getable, Login_Model_Setable, Login_Model_Selectable {
    
    /**
     *
     * @var type $registry_redirect
     * registry reirect handler
     */
    public $regstry_redirect;
    /**
     *
     * @var type $get_data
     * get data handler
     */
    public $get_data;
    /**
     *
     * @var type $message
     * message handler
     */
    public $message;
    /**
     *
     * @var type $set_user_data
     * set user data
     */
    public $set_user_data;
    
    public function main(array $variables = null) {
        //var_dump($variables);
        $this->check_data($variables['post']);
        $this->select_action($variables['post']);
        $this->set_data($variables);
    }
    
    /**
     * chack_data()
     * registry data initialization
     * 
     * @param array $variables
     */
    public function check_data(array $variables = null) {
       //var_dump($variables);
       if(!isset($variables['csrf_token'])){
            
            $this->regstry_redirect = new Login_Data_Registryredirect;
            $this->regstry_redirect->main($variables);
        
            
        }
    }
    
    /**
     * get_user_data()
     * check user data and show message
     * 
     * @param type $value
     * @param type $key
     */
    public function get_user_data($value, $key = null) {
        $variables[$key] = $value;
        $this->get_data = new Login_Data_Checkregisterdata;
        $user_data = $this->get_data->main($variables);
        if($user_data[$key] != null){
            $this->message = new Login_Data_Javascriptmessage;
            $this->message->message($value);
            $this->regstry_redirect = new Login_Data_Registryredirect;
            $this->regstry_redirect->main($variables);
        }
    }
    
    /**
     * set_data()
     * set registred data
     * 
     * @param array $variables
     */
    public function set_data(array $variables = null) {
        //var_dump($variables);
        $this->set_user_data = new Login_Data_Registred;
        $this->set_user_data->main($variables['post']);
    }
    
    /**
     * select_action()
     * check data from database
     * 
     * @param array $variables
     */
    public function select_action(array $variables = null) {
        //var_dump($variables);
        foreach($variables as $key => $value){
            if($key != 'csrf_token'){
                $this->get_user_data($value, $key);
            }
        }
    }

}
